﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using Yeap.Kernel.Security;

namespace Yeap.Kernel.Storage
{
    public class StudentRepository : IStudentRepository
    {
        private readonly UserRepository userRepository = new UserRepository();

        #region Implementation of IRepository<Student>

        public Student GetById(int id)
        {
            User idUser = userRepository.GetById(id);

            if (idUser == null)
            {
                return null;
            }

            if (idUser.UserType != (int?) UserTypes.Student)
            {
                return null;
            }

            return idUser.GetStudentForm();
        }

        public IEnumerable<Student> GetAll()
        {
            return userRepository.GetAll().Where(u => u.UserType.HasValue && u.UserType.Value == (int) UserTypes.Student).Select(u => u.GetStudentForm());
        }

        public IEnumerable<Student> Query(Expression<Func<Student, bool>> filter)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}